﻿'<Get Linux is a open source lightweight download client for operating systems.>
'    Copyright (C) <2014>  <Dev-fire>

'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.

'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>.
Public Class Main
    Public Website As String
    Public Download_32 As String
    Public Download_64 As String
    Public WithEvents CFG_WebClient As New WebClient
    Dim OS_CFG As String
    Public Selected_OS As String
    Public Connection As Boolean = False
    Public Request As WebRequest = Nothing
    Public Response As WebResponse = Nothing
    Public TotalFileSize As Long
    Public OS_Download As String
    Public OS_Download_Path As String
    Public Search_String As String
    Public File_Size_32 As String
    Public File_Size_64 As String
    Public Selected_Item As String
    Public Selected_Index As Integer
    Public OSs_Downloading As New ArrayList
    'SetBytes
    Function SetBytes(ByVal Bytes As Double) As String
        SetBytes = Nothing
        If Bytes >= 1073741824 Then
            SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") & " GB"
        ElseIf Bytes >= 1048576 Then
            SetBytes = Format(Bytes / 1024 / 1024, "#0.00") & " MB"
        ElseIf Bytes >= 1024 Then
            SetBytes = Format(Bytes / 1024, "#0.00") & " KB"
        ElseIf Bytes < 1024 Then
            SetBytes = Fix(Bytes) & " Bytes"
        End If
    End Function
    'On Startup
    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug.TextBox_Action_Log.Text = "<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action Log Started" & vbCrLf  'DEBUG ACTION LOG - Time Stamp
        Me.KeyPreview = True
        CFG_WebClient.Proxy = Nothing
        'Rename window and window label
        Me.Text = My.Application.Info.Title
        Label_Title.Text = My.Application.Info.Title
        'Check For Downloads Folder
        Splash.Loading = "Checking for Downloads folder..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking For Downloads Folder" & vbCrLf) 'DEBUG ACTION LOG - 
        If Not Directory.Exists(Environment.GetEnvironmentVariable("userprofile") & "\Downloads\") Then
            Directory.CreateDirectory(Environment.GetEnvironmentVariable("userprofile") & "\Downloads\")
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Downloads Folder Created" & vbCrLf) 'DEBUG ACTION LOG -
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Downloads Folder Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Check For Data Folder
        Splash.Loading = "Checking for Data folder..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking For Data Folder" & vbCrLf) 'DEBUG ACTION LOG - 
        If Not Directory.Exists(Application.StartupPath & "\Data\") Then
            Directory.CreateDirectory(Application.StartupPath & "\Data\")
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Data Folder Created" & vbCrLf) 'DEBUG ACTION LOG -
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Data Folder Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Check For Icons Folder
        Splash.Loading = "Checking for Icons folder..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking For Icons Folder" & vbCrLf) 'DEBUG ACTION LOG -
        If Not Directory.Exists(Application.StartupPath & "\Data\Icons\") Then
            Directory.CreateDirectory(Application.StartupPath & "\Data\Icons\")
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Icons Folder Created" & vbCrLf) 'DEBUG ACTION LOG -
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Icons Folder Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Check For Needed Libraries
        Splash.Loading = "Checking For Needed Libraries..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking For Needed Libraries" & vbCrLf) 'DEBUG ACTION LOG - 
        If Not File.Exists(Application.StartupPath & "\Microsoft.WindowsAPICodePack.Shell.dll") Then
            My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\Microsoft.WindowsAPICodePack.Shell.dll", My.Resources.Microsoft_WindowsAPICodePack_Shell, False)
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Library Created (Microsoft.WindowsAPICodePack.Shell.dll)" & vbCrLf) 'DEBUG ACTION LOG -
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Library (Microsoft.WindowsAPICodePack.Shell.dll) Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Checking For Microsoft.WindowsAPICodePack.dll
        If Not File.Exists(Application.StartupPath & "\Microsoft.WindowsAPICodePack.dll") Then
            My.Computer.FileSystem.WriteAllBytes(Application.StartupPath & "\Microsoft.WindowsAPICodePack.dll", My.Resources.Microsoft_WindowsAPICodePack, False)
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Library Created (Microsoft.WindowsAPICodePack.dll)" & vbCrLf) 'DEBUG ACTION LOG -
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Library (Microsoft.WindowsAPICodePack.dll) Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Check for Get Linux_OLD.exe
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking For Old File Version (Get Linux_OLD.exe)" & vbCrLf) 'DEBUG ACTION LOG -
        If File.Exists(Application.StartupPath & "\Get Linux_OLD.exe") Then
            File.Delete(Application.StartupPath & "\Get Linux_OLD.exe")
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Deleted Old File Version (Get Linux_OLD.exe)" & vbCrLf) 'DEBUG ACTION LOG - 
        Else
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: No Old File Version Found" & vbCrLf) 'DEBUG ACTION LOG -
        End If
        'Load settings
        Splash.Loading = "Loading: \Data\Settings.cfg"
        Splash.Loading_AccessControl()
        Data.Load_Settings()
        'Check if user is runing win-7 for Burn ISO
        If Not Environment.OSVersion.Version.ToString.StartsWith("6.1") Then
            Settings.RadioButton_Burn_ISO.Enabled = False
            ToolTip_Main.SetToolTip(Settings.RadioButton_Burn_ISO, "Win-7 Only!")
            If Settings.RadioButton_Burn_ISO.Checked Then
                Settings.RadioButton_Do_Nothing.Checked = True
            End If
        End If
        'Check Server Connection
        Splash.Loading = "Checking Connection..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Checking Connection" & vbCrLf) 'DEBUG ACTION LOG - 
        Data.Check_Connection()
        'Verifying Server Connection
        Splash.Loading = "Verifying Connection..."
        Splash.Loading_AccessControl()
        Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Verifying Connection" & vbCrLf) 'DEBUG ACTION LOG - 
        If Connection = True Then
            Splash.Loading = "Connected"
            Splash.Loading_AccessControl()
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: Connected" & vbCrLf) 'DEBUG ACTION LOG - 
        Else
            Splash.Loading = "Connection: Failed..."
            Splash.Loading_AccessControl()
            Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Error: Connection Failed" & vbCrLf) 'DEBUG ACTION LOG - 
            'Show NotifyIcon_Main
            NotifyIcon_Main.Visible = True
            NotifyIcon_Main.BalloonTipText = "Connection: Failed..."
            NotifyIcon_Main.ShowBalloonTip(1500)
            System.Threading.Thread.Sleep(1500)
            Exit Sub
        End If
        'Build OSL
        Splash.Loading = "Loading: Operating Systems List"
        Splash.Loading_AccessControl()
        Data.OSL_List()
        'Clean_Icons
        Splash.Loading = "Cleaning Icons"
        Splash.Loading_AccessControl()
        Data.Clean_Icons()
        'Auto select OS
        Splash.Loading = "Selecting random OS..."
        Splash.Loading_AccessControl()
        Data.Auto_Select_OS()
        'Play startup sound
        Data.Play_Startup_Sound()
        'Show NotifyIcon Main
        NotifyIcon_Main.Visible = True
    End Sub
    'On Closing
    Private Sub Main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If OSs_Downloading.Count < 1 And Debug.Visible = False And News.Visible = False Then
            NotifyIcon_Main.Icon = Nothing
            Debug.Close()
            News.Close()
        Else
            Me.WindowState = FormWindowState.Minimized
            Me.Hide()
            Me.NotifyIcon_Main.BalloonTipText = "Closed to tray."
            Me.NotifyIcon_Main.ShowBalloonTip(1500)
            'Do Not Close
            e.Cancel = True
        End If
    End Sub
    'Download Button
    Private Sub Button_Download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Download.Click
        If Not Selected_Index = -1 Then 'Check for a selected OS
            Dim str As String
            For Each str In OSs_Downloading
                If Selected_OS = str Then
                    MsgBox("This operating system is already downloading downloading!", MsgBoxStyle.Information)
                    Exit Sub
                End If
            Next
            If Settings.CheckBox_Download_Enabled.Checked = True Then 'If Enabled
                If Directory.Exists(Settings.TextBox_Download_Path.Text) Then 'If Download Directory Exists
                    OS_Download_Path = Settings.TextBox_Download_Path.Text 'Set String
                Else
                    If Settings.RadioButton_Download_Default.Checked = True Then
                        Directory.CreateDirectory(Environment.GetEnvironmentVariable("userprofile") & "\Downloads\")
                        OS_Download_Path = Settings.TextBox_Download_Path.Text 'Set String
                    Else
                        MsgBox("Download directory not found!" & vbCrLf & "Please select a download directory.", MsgBoxStyle.Information)
                        If Settings.FolderBrowserDialog_Download_Directory.ShowDialog() = Windows.Forms.DialogResult.OK Then 'Open Folder Dialog
                            OS_Download_Path = Settings.FolderBrowserDialog_Download_Directory.SelectedPath & "\"
                            Settings.TextBox_Download_Path.Text = OS_Download_Path 'Set String
                        Else
                            Exit Sub
                        End If
                    End If
                End If
            Else
                If Settings.FolderBrowserDialog_Download_Directory.ShowDialog() = Windows.Forms.DialogResult.OK Then 'Open Folder Dialog
                    OS_Download_Path = Settings.FolderBrowserDialog_Download_Directory.SelectedPath & "\"
                Else
                    Exit Sub
                End If
            End If
            'Clear FolderBrowserDialog Directory
            Settings.FolderBrowserDialog_Download_Directory.SelectedPath = Nothing
            Dim t As New Thread(AddressOf Requesting_Thread)
            t.Priority = ThreadPriority.Normal
            t.Start()
            t.Join()
            If TotalFileSize > 1 Then
                Dim New_Downloading_Window As New Downloading
                New_Downloading_Window.OS_Download = OS_Download
                New_Downloading_Window.OS_Download_Path = OS_Download_Path
                'Download Info
                New_Downloading_Window.Label_Title.Text = Nothing
                New_Downloading_Window.TotalFileSize = TotalFileSize
                New_Downloading_Window.Website = Website
                New_Downloading_Window.OS_Name = Selected_OS
                New_Downloading_Window.Label_Name.Text = Selected_OS
                New_Downloading_Window.Label_Version.Text = TextBox_Version.Text
                New_Downloading_Window.Label_File_Name.Text = OS_Download
                New_Downloading_Window.Label_Total_Size.Text = SetBytes(TotalFileSize)
                New_Downloading_Window.Label_Desktop.Text = TextBox_Desktop.Text
                If RadioButton_32_Bit.Checked = True Then
                    New_Downloading_Window.Label_Architecture.Text = "32 Bit"
                Else
                    New_Downloading_Window.Label_Architecture.Text = "64 Bit"
                End If
                New_Downloading_Window.ToolTip1.SetToolTip(New_Downloading_Window.PictureBox_Website, Selected_OS & " website")
                New_Downloading_Window.PictureBox_OS_Logo.Image = ImageList_Main.Images.Item(Selected_OS)
                New_Downloading_Window.PictureBox_OS_Image.ImageLocation = PictureBox_OS_Image.ImageLocation
                OSs_Downloading.Add(Selected_OS)
                New_Downloading_Window.Show()
                'Clear TotalFileSize
                TotalFileSize = Nothing
                'Update Variables on debug window
                Debug.Variables()
            End If
        End If
    End Sub
    'Exit | ContextMenuItem
    Private Sub ContextMenuItem_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_Exit.Click
        If OSs_Downloading.Count < 1 Then
            Close()
        Else
            If Me.Visible Then
                Me.WindowState = FormWindowState.Minimized
                Me.Hide()
                Me.NotifyIcon_Main.BalloonTipText = "Closed to tray."
                Me.NotifyIcon_Main.ShowBalloonTip(1500)
            End If
        End If
    End Sub
    'Settings | ContextMenuItem
    Private Sub ContextMenuItem_Settings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_Settings.Click
        If Settings.Visible = False Then
            Settings.ShowDialog()
        Else
            Settings.Close()
        End If
    End Sub
    'Check For Updates | ContextMenuItem
    Private Sub ContextMenuItem_CheckForUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_CheckForUpdates.Click
        Data.Check_For_Updates()
    End Sub
    'About | ContextMenuItem
    Private Sub ContextMenuItem_About_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_About.Click
        If About.Visible = False Then
            About.ShowDialog()
        Else
            About.Close()
        End If
    End Sub
    'Trayicon Show / Hide Main Window
    Private Sub NotifyIcon_Main_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon_Main.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Data.Show_Hide_Main_Window()
        End If
    End Sub
    'Settings | ToolStripMenuItem
    Private Sub ToolStripMenuItem_Settings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem_Settings.Click
        If Settings.Visible = False Then
            Settings.ShowDialog()
        Else
            Settings.Close()
        End If
    End Sub
    'Check For Updates | ToolStripMenuItem
    Private Sub ToolStripMenuItem_Check_For_Updates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Data.Check_For_Updates()
    End Sub
    'About | ToolStripMenuItem
    Private Sub ToolStripMenuItem_About_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem_About.Click
        If About.Visible = False Then
            About.ShowDialog()
        Else
            About.Close()
        End If
    End Sub
    'Search For OS
    Private Sub TextBox_Search_For_OS_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox_Search_For_OS.KeyDown
        If e.KeyData = Keys.Enter Then
            If TextBox_Search_For_OS.Text.Length > 0 Then
                NotifyIcon_Main.BalloonTipText = "Searching for Operating System."
                NotifyIcon_Main.ShowBalloonTip(1500)
                NotifyIcon_Main.BalloonTipText = Nothing
                Dim item As ListViewItem
                For Each item In ListView1.Items
                    If item.Text.ToLower = TextBox_Search_For_OS.Text.ToLower Then
                        ListView1.Items(item.Index).Selected = True
                        ListView1.Items(item.Index).EnsureVisible()
                        ListView1.Select()
                        NotifyIcon_Main.BalloonTipText = "Operating System found."
                        NotifyIcon_Main.ShowBalloonTip(1500)
                        NotifyIcon_Main.BalloonTipText = Nothing
                        TextBox_Search_For_OS.Clear()
                        Exit Sub
                    End If
                Next
                'Show message OS found
                NotifyIcon_Main.BalloonTipText = "Operating System not found."
                NotifyIcon_Main.ShowBalloonTip(1500)
                NotifyIcon_Main.BalloonTipText = Nothing
                TextBox_Search_For_OS.Clear()
            End If
        End If
    End Sub
    'Reconnect
    Private Sub ToolStripMenuItem_Reconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem_Reconnect.Click
        Data.Reconnect()
    End Sub
    'RadioButton 32 Bit
    Private Sub RadioButton_32_Bit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton_32_Bit.CheckedChanged
        If RadioButton_32_Bit.Checked = True Then
            TextBox_File_Size.Text = File_Size_32
            'Set OS_Download
            OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_32))
            If Form.ActiveForm.Name = "Main" Then
                'Update Variables on debug window
                Debug.Variables()
            End If
        End If
    End Sub
    'RadioButton 64 Bit
    Private Sub RadioButton_64_Bit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton_64_Bit.CheckedChanged
        If RadioButton_64_Bit.Checked = True Then
            TextBox_File_Size.Text = File_Size_64
            'Set OS_Download
            OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_64))
            If Form.ActiveForm.Name = "Main" Then
                'Update Variables on debug window
                Debug.Variables()
            End If
        End If
    End Sub
    'News | ToolStripMenuItem
    Private Sub ToolStripMenuItem_News_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem_News.Click
        If News.Visible = False Then
            News.Show()
        End If
    End Sub
    'News | ContextMenuItem
    Private Sub ContextMenuItem_News_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_News.Click
        If News.Visible = False Then
            News.Show()
        End If
    End Sub
    'Close
    Private Sub PictureBox_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox_Close.Click
        If OSs_Downloading.Count < 1 Then
            Close()
        Else
            Me.WindowState = FormWindowState.Minimized
            Me.Hide()
            Me.NotifyIcon_Main.BalloonTipText = "Closed to tray."
            Me.NotifyIcon_Main.ShowBalloonTip(1500)
        End If
    End Sub
    'Move Window - Panel
    Private Sub Panel_Main_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel_Main.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Panel_Main.Capture = False
            Const WM_NCLBUTTONDOWN As Integer = &HA1S
            Const HTCAPTION As Integer = 2
            Dim msg As Message = Message.Create(Me.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero)
            Me.DefWndProc(msg)
        End If
    End Sub
    'Move Window - Label Title
    Private Sub Label_Title_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label_Title.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Label_Title.Capture = False
            Const WM_NCLBUTTONDOWN As Integer = &HA1S
            Const HTCAPTION As Integer = 2
            Dim msg As Message = Message.Create(Me.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero)
            Me.DefWndProc(msg)
        End If
    End Sub
    'Minimize
    Private Sub PictureBox_Minimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox_Minimize.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub
    'Go To Website
    Private Sub PictureBox2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox_OS_Image.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Left Then
            If Not Selected_Index = -1 Then
                Try
                    If Not Website = Nothing Then
                        NotifyIcon_Main.BalloonTipText = "Opening " & Selected_OS.ToLower & " website."
                        NotifyIcon_Main.ShowBalloonTip(1500)
                        Process.Start(Website)
                    End If
                Catch Ex As Exception
                    MsgBox(Ex.Message, MsgBoxStyle.Critical)
                End Try
            End If
        End If
    End Sub
    'Selected item and index
    Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
        If e.Item.Selected Then
            Selected_Item = e.Item.Text
            Selected_Index = e.ItemIndex
        End If
        If Not Selected_Index = -1 Then 'Check for a selected OS
            If Not Selected_OS = Selected_Item Then
                Selected_OS = Nothing
                Selected_OS = Selected_Item
                Try
                    'Clear GUI And Data
                    Data.Clear_GUI_And_Data()
                    Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Action: Loading OS Data (" & Selected_OS & ")" & vbCrLf)  'DEBUG ACTION LOG -
                    'Set Image
                    PictureBox_OS_Image.ImageLocation = ("https://get-linux.googlecode.com/svn/trunk/Data/Operating Systems/" & Selected_OS & "/Image.jpg")
                    'Store Stream
                    Dim OS_CFG_Stream As Stream = CFG_WebClient.OpenRead("https://get-linux.googlecode.com/svn/trunk/Data/Operating Systems/" & Selected_OS & "/OS.cfg")
                    'Read Stream
                    Dim OS_Reader As New StreamReader(OS_CFG_Stream)
                    OS_CFG = OS_Reader.ReadToEnd
                    OS_Reader.Close() 'Close StreamReader
                    OS_CFG_Stream.Close() 'Close Stream
                    Dim CFG_Line() As String = Split(OS_CFG, vbCrLf.ToCharArray)
                    OS_CFG = Nothing
                    'About //Line 0
                    If CFG_Line(0).StartsWith("About:") Then
                        CFG_Line(0) = CFG_Line(0).Substring(6)
                        If Not CFG_Line(0) = Nothing Then
                            TextBox_About.Text = CFG_Line(0).ToString
                        Else
                            CFG_Line = Nothing
                            Data.Bad_OS_CFG()
                            Exit Sub
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Origin //Line 1
                    If CFG_Line(1).StartsWith("Origin:") Then
                        CFG_Line(1) = CFG_Line(1).Substring(7)
                        If Not CFG_Line(1) = Nothing Then
                            TextBox_Origin.Text = CFG_Line(1).ToString
                        Else
                            CFG_Line = Nothing
                            Data.Bad_OS_CFG()
                            Exit Sub
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Version //Line 2
                    If CFG_Line(2).StartsWith("Version:") Then
                        CFG_Line(2) = CFG_Line(2).Substring(8)
                        If Not CFG_Line(2) = Nothing Then
                            TextBox_Version.Text = CFG_Line(2).ToString
                        Else
                            CFG_Line = Nothing
                            Data.Bad_OS_CFG()
                            Exit Sub
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Desktop //Line 3
                    If CFG_Line(3).StartsWith("Desktop:") Then
                        CFG_Line(3) = CFG_Line(3).Substring(8)
                        If Not CFG_Line(3) = Nothing Then
                            TextBox_Desktop.Text = CFG_Line(3).ToString
                        Else
                            CFG_Line = Nothing
                            Data.Bad_OS_CFG()
                            Exit Sub
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Website //Line 4
                    If CFG_Line(4).StartsWith("Website:") Then
                        CFG_Line(4) = CFG_Line(4).Substring(8)
                        If CFG_Line(4).StartsWith("http://") Or CFG_Line(4).StartsWith("https://") Then
                            Website = CFG_Line(4).ToString
                        Else
                            CFG_Line = Nothing
                            Data.Bad_OS_CFG()
                            Exit Sub
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Download_32 //Line 5
                    If CFG_Line(5).StartsWith("Download_32:") Then
                        CFG_Line(5) = CFG_Line(5).Substring(12)
                        If CFG_Line(5).StartsWith("http://") Or CFG_Line(5).StartsWith("https://") Then
                            Download_32 = CFG_Line(5).ToString
                            If RadioButton_32_Bit.Enabled = False Then
                                RadioButton_32_Bit.Enabled = True
                            End If
                        Else
                            If CFG_Line(5) = Nothing Then
                                If RadioButton_32_Bit.Enabled = True Then
                                    RadioButton_32_Bit.Enabled = False
                                End If
                            Else
                                CFG_Line = Nothing
                                Data.Bad_OS_CFG()
                                Exit Sub
                            End If
                        End If
                    End If
                    'FileSize_32 //Line 6
                    If CFG_Line(6).StartsWith("FileSize_32:") Then
                        CFG_Line(6) = CFG_Line(6).Substring(12)
                        If Not CFG_Line(6) = Nothing Then
                            File_Size_32 = CFG_Line(6).ToString
                            TextBox_File_Size.Text = File_Size_32
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Download_64 //Line 7
                    If CFG_Line(7).StartsWith("Download_64:") Then
                        CFG_Line(7) = CFG_Line(7).Substring(12)
                        If CFG_Line(7).StartsWith("http://") Or CFG_Line(7).StartsWith("https://") Then
                            Download_64 = CFG_Line(7).ToString
                            If RadioButton_64_Bit.Enabled = False Then
                                RadioButton_64_Bit.Enabled = True
                            End If
                        Else
                            If CFG_Line(7) = Nothing Then
                                If RadioButton_64_Bit.Enabled = True Then
                                    RadioButton_64_Bit.Enabled = False
                                End If
                            Else
                                CFG_Line = Nothing
                                Data.Bad_OS_CFG()
                                Exit Sub
                            End If
                        End If
                    End If
                    'FileSize_64 //Line 8
                    If CFG_Line(8).StartsWith("FileSize_64:") Then
                        CFG_Line(8) = CFG_Line(8).Substring(12)
                        If Not CFG_Line(8) = Nothing Then
                            File_Size_64 = CFG_Line(8).ToString
                        End If
                    Else
                        CFG_Line = Nothing
                        Data.Bad_OS_CFG()
                        Exit Sub
                    End If
                    'Select 32 or 64
                    If RadioButton_32_Bit.Enabled = False Then
                        RadioButton_64_Bit.Checked = True
                    End If
                    If RadioButton_64_Bit.Enabled = False Then
                        RadioButton_32_Bit.Checked = True
                    End If
                    'Set OS_Download
                    If RadioButton_32_Bit.Checked = True Then
                        TextBox_File_Size.Text = File_Size_32
                        OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_32))
                    End If
                    If RadioButton_64_Bit.Checked = True Then
                        TextBox_File_Size.Text = File_Size_64
                        OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_64))
                    End If
                    'Clear array
                    CFG_Line = Nothing
                    'Set ToolTips
                    ToolTip_Main.SetToolTip(PictureBox_OS_Image, Selected_OS & " website.")
                    ToolTip_Main.SetToolTip(Button_Download, "Download " & Selected_OS & ".")
                    Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Information: OS Data Loaded (" & Selected_OS & ")" & vbCrLf)  'DEBUG ACTION LOG -
                Catch Wx As System.Net.WebException
                    NotifyIcon_Main.BalloonTipText = "Connection Failed: " & Wx.Message
                    NotifyIcon_Main.ShowBalloonTip(1500)
                    Debug.TextBox_Action_Log.AppendText("<" & Now.ToString("hh:mm:ss.fff tt") & "> " & "Error: Connection Failed (" & Wx.Message & ")" & vbCrLf) 'DEBUG ACTION LOG -
                    'Update Variables on debug window
                    Debug.Variables()
                Catch Ex As Exception
                    MsgBox(Ex.Message)
                    Data.Bad_OS_CFG()
                End Try
            End If
        End If
    End Sub
    'Button Download MouseHover
    Private Sub Button_Download_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Download.MouseHover
        Button_Download.FlatAppearance.BorderColor = Color.SteelBlue
    End Sub
    'Button Download MouseLeave
    Private Sub Button_Download_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Download.MouseLeave
        Button_Download.FlatAppearance.BorderColor = Panel_Main.BackColor
    End Sub
    'AppIcon Click - Show/Hide Main Window
    Private Sub PictureBox_AppIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox_AppIcon.Click
        Data.Show_Hide_Main_Window()
    End Sub
    'Open Download Directory
    Private Sub ToolStripMenuItem_Downloads_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem_Downloads.Click
        Try
            If Directory.Exists(Settings.TextBox_Download_Path.Text.ToString) Then
                Process.Start(Settings.TextBox_Download_Path.Text.ToString)
            Else
                MsgBox("Download directory not found!" & vbCrLf & "Default download directory will be selected and loaded.", MsgBoxStyle.Information)
                Settings.RadioButton_Download_Default.Checked = True
                Process.Start(Settings.TextBox_Download_Path.Text.ToString)
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    'Open Download Directory
    Private Sub ContextMenuItem_Downloads_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuItem_Downloads.Click
        Try
            If Directory.Exists(Settings.TextBox_Download_Path.Text.ToString) Then
                Process.Start(Settings.TextBox_Download_Path.Text.ToString)
            Else
                MsgBox("Download directory not found!" & vbCrLf & "Default download directory will be selected and loaded.", MsgBoxStyle.Information)
                Settings.RadioButton_Download_Default.Checked = True
                Process.Start(Settings.TextBox_Download_Path.Text.ToString)
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    'Main KeyDown
    Private Sub Main_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
        'Ctrl+~ Show Debug window
        If e.Control And e.KeyCode = Keys.Oem3 Then
            If Not Debug.Visible Then
                Debug.Show()
            End If
        End If
        'Ctrl+Home Open Downloads
        If e.Control And e.KeyCode = Keys.Home Then
            ToolStripMenuItem_Downloads.PerformClick()
        End If
        'Ctrl+D Download
        If e.Control And e.KeyCode = Keys.D Then
            Button_Download.PerformClick()
        End If
        'Ctrl+R Reconnect
        If e.Control And e.KeyCode = Keys.R Then
            ToolStripMenuItem_Reconnect.PerformClick()
        End If
        'Ctrl+S Settings
        If e.Control And e.KeyCode = Keys.S Then
            ToolStripMenuItem_Settings.PerformClick()
        End If
        'Ctrl+N News
        If e.Control And e.KeyCode = Keys.N Then
            ToolStripMenuItem_News.PerformClick()
        End If
        'Ctrl+U Check for updates
        If e.Control And e.KeyCode = Keys.U Then
            CheckForUpdatesToolStripMenuItem.PerformClick()
        End If
        'Ctrl+A About
        If e.Control And e.KeyCode = Keys.A Then
            About.ShowDialog()
        End If
    End Sub
    'Minimize Blue
    Private Sub PictureBox_Minimize_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox_Minimize.MouseHover
        PictureBox_Minimize.Image = My.Resources.Minimize_Blue
    End Sub
    'Minimize Grey
    Private Sub PictureBox_Minimize_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox_Minimize.MouseLeave
        PictureBox_Minimize.Image = My.Resources.Minimize_Grey
    End Sub
    'Form Deactivate Close Grey
    Private Sub Main_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        PictureBox_Close.Image = My.Resources.Close_Grey
    End Sub
    'Form Activated Close Red
    Private Sub Main_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        PictureBox_Close.Image = My.Resources.Close_Red
    End Sub
    'Requesting Thread
    Private Sub Requesting_Thread()
        Try
            NotifyIcon_Requesting.Visible = True
            NotifyIcon_Requesting.BalloonTipText = "Requesting file from server."
            NotifyIcon_Requesting.ShowBalloonTip(1500)
            '32 Bit OS Download
            If RadioButton_32_Bit.Checked = True Then
                OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_32))
                Request = WebRequest.Create(Download_32)
            End If
            '64 Bit OS Download
            If RadioButton_64_Bit.Checked = True Then
                OS_Download = System.Web.HttpUtility.UrlDecode(Path.GetFileName(Download_64))
                Request = WebRequest.Create(Download_64)
            End If
            'If required by the server, set the credentials
            Request.Credentials = CredentialCache.DefaultCredentials
            Request.Timeout = 6000
            Response = Request.GetResponse
            TotalFileSize = Response.ContentLength
            Response.Close()
            NotifyIcon_Requesting.Visible = False
        Catch Wx As System.Net.WebException
            NotifyIcon_Requesting.Visible = False
            NotifyIcon_Main.BalloonTipText = "Connection Failed: " & Wx.Message
            NotifyIcon_Main.ShowBalloonTip(1500)
        Catch Ex As Exception
            NotifyIcon_Requesting.Visible = False
            MsgBox(Ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    'Check For Updates | ToolStripMenuItem
    Private Sub CheckForUpdatesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdatesToolStripMenuItem.Click
        Data.Check_For_Updates()
    End Sub
End Class